package com.ruoyi.cms.controller;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baidu.ueditor.ActionEnter;
import com.ruoyi.common.core.controller.BaseController;

/**
 * UeditorController
 * 
 * @author wujiyue
 * @date 2019-11-26
 */
@Controller
@RequestMapping("/cms/ueditor")
public class UEditorController extends BaseController
{
   
	  @GetMapping("/config")
	    public void config(HttpServletRequest request, HttpServletResponse response) {
	        doExe(request, response);
	    }

	    @PostMapping("/config")
	    public void postConfig(HttpServletRequest request, HttpServletResponse response) {
	        doExe(request, response);
	    }

	    private void doExe(HttpServletRequest request, HttpServletResponse response) {
	        response.setContentType("application/json");
	        String rootPath = request.getSession().getServletContext().getRealPath(File.separator);
	        try {
	            String exec = new ActionEnter(request, rootPath).exec();
	            PrintWriter writer = response.getWriter();
	            writer.write(exec);
	            writer.flush();
	            writer.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	    }
}
